package com.yunqing.restkeeper.web.common;

import com.yunqing.restkeeper.common.utils.PinyinUtil;
import com.yunqing.restkeeper.common.utils.Result;
import com.yunqing.restkeeper.common.utils.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CommonController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/7/25
 */
@Slf4j
@RestController
@RequestMapping("/common")
@Tag(name = "通用接口")
public class CommonController {

    @GetMapping("/toHanyuPinyin/{chineseLanguage}")
    @Operation(summary = "中文转换汉语拼音")
    @Parameter(in = ParameterIn.PATH, name = "chineseLanguage", description = "汉语拼音", required = true, schema = @Schema(type = "String"))
    public Result toHanyuPinyin(@PathVariable String chineseLanguage) throws BadHanyuPinyinOutputFormatCombination {
        Result result = new Result();
        result.setStatus(ResultCode.success);
        result.setDesc("ok");
        result.setData(PinyinUtil.toHanyuPinyin(chineseLanguage));
        return result;
    }

}
